package com.lzx.mumianaicodegenerator.controller;

import com.lzx.mumianaicodegenerator.ai.AiTextOptimizerService;
import com.lzx.mumianaicodegenerator.ai.AiTextOptimizerServiceFactory;
import com.lzx.mumianaicodegenerator.common.BaseResponse;
import com.lzx.mumianaicodegenerator.common.ResultUtils;
import com.lzx.mumianaicodegenerator.exception.BusinessException;
import com.lzx.mumianaicodegenerator.exception.ErrorCode;
import com.lzx.mumianaicodegenerator.exception.ThrowUtils;
import com.lzx.mumianaicodegenerator.model.entity.App;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/text")
public class TextController {
    @Resource
    private AiTextOptimizerServiceFactory aiTextOptimizerServiceFactory;
    @PostMapping("/optimize")
    public BaseResponse<String> optimize(String userPrompt) {
        ThrowUtils.throwIf(userPrompt == null, ErrorCode.PARAMS_ERROR);
        AiTextOptimizerService aiTextOptimizerService = aiTextOptimizerServiceFactory.createAiTextOptimizerService();
        String prompted = aiTextOptimizerService.promptOptimize(userPrompt);
        if (prompted == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "prompted is null");
        }
        return ResultUtils.success(prompted);
    }

}
